// @Author EthanScriptOn
// @Desc
package tool

import (
	"gitee.com/fatzeng/srf_switch_basic_components/custom_exp"
)

// ErrorCollection Error collection
type ErrorCollection struct {
	errors *custom_exp.MultiError
}

// WithErrorCollector Collect errors
func (e *ErrorCollection) WithErrorCollector(err error) {
	if err == nil {
		return
	}
	HandleErr(&err)
	if e.errors == nil {
		e.errors = custom_exp.GenerateMultiError(err)
		return
	}
	e.errors.AddError(err)
}

// GetError Get the error
func (e *ErrorCollection) GetError() error {
	if e.errors == nil || len(e.errors.GetErrors()) <= 0 {
		return nil
	}
	return e.errors
}
